home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / libsipp / smalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-03  |  1.5 KB  |  76 lines

  1. /**
  2.  ** sipp - SImple Polygon Processor
  3.  **
  4.  **  A general 3d graphic package
  5.  **
  6.  **  Copyright Equivalent Software HB  1992
  7.  **
  8.  ** This program is free software; you can redistribute it and/or modify
  9.  ** it under the terms of the GNU General Public License as published by
  10.  ** the Free Software Foundation; either version 1, or any later version.
  11.  ** This program is distributed in the hope that it will be useful,
  12.  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  ** GNU General Public License for more details.
  15.  ** You can receive a copy of the GNU General Public License from the
  16.  ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  **/
  18.  
  19. /**
  20.  ** smalloc.c - "Safe" malloc and calloc.
  21.  **/
  22.  
  23. #include <malloc.h>
  24. #include <stdio.h>
  25.  
  26.  
  27. char *
  28. smalloc(size)
  29.     int size;
  30. {
  31.     char *p;
  32.  
  33.     p = (char *)malloc(size);
  34.     if (p == NULL) {
  35.         fprintf(stderr, "smalloc(): Out of memory.\n");
  36.         exit(1);
  37.     }
  38.  
  39.     return p;
  40. }
  41.  
  42.  
  43. char *
  44. scalloc(size, itemsize)
  45.     int size;
  46.     int itemsize;
  47. {
  48.     char *p;
  49.  
  50.     p = (char *)calloc(size, itemsize);
  51.     if (p == NULL) {
  52.         fprintf(stderr, "scalloc(): Out of memory.\n");
  53.         exit(1);
  54.     }
  55.  
  56.     return p;
  57. }
  58.  
  59.  
  60. char *
  61. srealloc(ptr, size)
  62.     char *ptr;
  63.     int   size;
  64. {
  65.     char *p;
  66.  
  67.     p = realloc(ptr, size);
  68.     if (p == NULL) {
  69.         fprintf(stderr, "srealloc(): Out of memory.\n");
  70.         exit(1);
  71.     }
  72.  
  73.     return p;
  74. }
  75.  
  76.